package com.etnet.streamserver.format;

import com.etnet.streamserver.exception.ParamException;
import com.etnet.streamserver.format.impl.ArrayCSVFormatter;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;

public class FormatterFactory {
    private static Logger log = Logger.getLogger(FormatterFactory.class.getName());
    private static Map<String, IFormatter<?>> register = new HashMap<String, IFormatter<?>>();

    static {
        register.put("arraycsv", new ArrayCSVFormatter());
    }

    public static IFormatter getFormatter(String name) {
        IFormatter formatter = register.get(name.toLowerCase());
        try {
            if (formatter == null) {
                throw new ParamException(name + " formatter is null", null);
            }
        } catch (ParamException e) {
            log.error("Error:" + e.getMessage());
        }
        return formatter;
    }
}